/**
 * 考試管理初始化
 */
var AnsweList = {
    id: "AnswerListTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    AnsweListData: {},
    layerIndex: -2
};
var ProType = {
        type: null
    }
;
/**
 * 初始化表格的列
 */
AnsweList.initColumn = function () {
    return [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle', hidden: true},
        {
            title: '', field: 'optionsA', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                if (value) {
                    return "<input type=\"checkbox\" id='checkboxA'/>" + "A"
                } else {
                    return "";
                }
            }
        },
        {
            title: '', field: 'optionsB', align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (value) {
                return "<input type=\"checkbox\" id='checkboxB'/>" + "B"
            } else {
                return "";
            }
        }
        },
        {
            title: '', field: 'optionsC', align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (value) {
                return "<input type=\"checkbox\" id='checkboxC'/>" + "C"
            } else {
                return "";
            }
        }
        },
        {
            title: '', field: 'optionsD', align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (value) {
                return "<input type=\"checkbox\" id='checkboxD'/>" + "D"
            } else {
                return "";
            }
        }
        },
        {
            title: '', field: 'optionsE', align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (value) {
                return "<input type=\"checkbox\" id='checkboxE'/>" + "E"
            } else {
                return "";
            }
        }
        },
        {
            title: '', field: 'optionsF', align: 'center', valign: 'middle', formatter: function (value, row, index) {
            if (value) {
                return "<input type=\"checkbox\" id='checkboxF'/>" + "F"
            } else {
                return "";
            }
        }
        },
    ];
};

/**
 * 检查是否选中
 */
AnsweList.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        AnsweList.seItem = selected[0];
        return true;
    }
};

AnsweList.formParams = function () {
    var queryData = {};
    return queryData;
}
/**
 * 关闭此对话框
 */
AnsweList.close = function () {
    parent.layer.close(window.parent.Testing.layerIndex);
}
/**
 * 关闭此对话框
 */
AnsweList.close1 = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

AnsweList.choose = function () {
    var addressID = $("input[name='test']:checked").val();
    document.getElementById('userAnswer').value += addressID;
    if (addressID == "" || addressID == null) {
        alert("请选择！");
        return false;
    }
    this.clearData();
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/answerList/update", function (data) {
        AnsweList.close();
    }, function (data) {
        Feng.error("选择失败!内部故障" + data.responseJSON.message + "!");
    });
    ajax.set(this.AnsweListData);
    ajax.start();
}
/**
 * 点击添加考试
 */
AnsweList.choose1 = function () {
    var testNumber = $('#testNumber').val()
    document.getElementById('userAnswer').value = "";
    if ($('#checkboxA').is(':checked')) {
        document.getElementById('userAnswer').value += "A"
        window.parent.document.getElementById("radio1A" + testNumber + "").style.background = "blue";
    }else {
        window.parent.document.getElementById("radio1A" + testNumber + "").style.background = "bottom";
    }
    if ($('#checkboxB').is(':checked')) {
        document.getElementById('userAnswer').value += "B"
        window.parent.document.getElementById("radio1B" + testNumber + "").style.background = "blue";
    }else {
        window.parent.document.getElementById("radio1B" + testNumber + "").style.background = "bottom";
    }
    if ($('#checkboxC').is(':checked')) {
        document.getElementById('userAnswer').value += "C"
        window.parent.document.getElementById("radio1C" + testNumber + "").style.background = "blue";
    }else {
        window.parent.document.getElementById("radio1C" + testNumber + "").style.background = "bottom";
    }
    if ($('#checkboxD').is(':checked')) {
        document.getElementById('userAnswer').value += "D"
        window.parent.document.getElementById("radio1D" + testNumber + "").style.background = "blue";
    }else {
        window.parent.document.getElementById("radio1D" + testNumber + "").style.background = "bottom";
    }
    var userAnswer = $('#userAnswer').val()
    if (userAnswer == "" || userAnswer == null) {
        alert("请选择！");
        return false;
    }
    this.clearData();
    this.collectData();
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/answerList/updates", function (data) {
        // window.parent.myslider.next();
        AnsweList.close1();
    }, function (data) {
        Feng.error("选择失败!内部故障" + data.responseJSON.message + "!");
    });
    ajax.set(this.AnsweListData);
    ajax.start();
};
AnsweList.set = function (key, val) {
    this.AnsweListData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}
/**
 * 清除数据
 */
AnsweList.clearData = function () {
    this.AnsweListData = {};
}
/**
 * 收集数据
 */
AnsweList.collectData = function () {
    this.set('userAnswer').set('questionId').set('theTestId').set('id').set('testNumber');
}
var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

$(function () {
    var defaultColunms = AnsweList.initColumn();
    var table = new BSTable(AnsweList.id, "/answerList/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(AnsweList.formParams());
    AnsweList.table = table.init();
});
